//
//  VCAgeView.m
//  ByVoiceChat
//
//  Created by wlf on 2022/4/19.
//

#import "PlayMulitpleView.h"

@implementation PlayMulitpleView

- (void)showIn:(UIView *)view{
    [view addSubview:self];
    self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
    self.mulitStr = @"0.75";
}
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {

        UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 300, SCREEN_WIDTH,300)];
        contentView.backgroundColor = [UIColor whiteColor];
        contentView.layer.cornerRadius = 10;
        contentView.layer.masksToBounds = YES;
        [self addSubview:contentView];
    
        self.mulitPick = [[UIPickerView alloc] init];
        self.mulitPick.frame = CGRectMake((SCREEN_WIDTH - 100) / 2, 60, 100, 200);
        
        self.mulitPick.delegate = self;
        self.mulitPick.dataSource = self;
        [contentView addSubview:self.mulitPick];
        
        CGFloat hegith = 50;
        self.cancleBtn.frame = CGRectMake(20, 0, 50, hegith);
        self.continueBtn.frame = CGRectMake((SCREEN_WIDTH - 20 - 50),  0, 50, 50);
        [contentView addSubview:self.cancleBtn];
        [contentView addSubview:self.continueBtn];
    }
    return self;
}

#pragma mark - getters and setters
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return self.dataSource.count;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
    return 45;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{
    return  103;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    NSString *str = self.dataSource[row];
    return str;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    NSString *str = self.dataSource[row];
    
    self.mulitStr = str;
}


- (void)cancleBtnClick{
    [self removeFromSuperview];
}
- (void)continueBtnClick{
    if (self.mulitBlock) {
        self.mulitBlock(self.mulitStr);
    }
    [self removeFromSuperview];
}
- (UIButton *)continueBtn
{
    if (!_continueBtn) {
        _continueBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _continueBtn.frame = CGRectZero;
        _continueBtn.titleLabel.font = [UIFont boldSystemFontOfSize:18];
        [_continueBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [_continueBtn setTitle:@"确定" forState:UIControlStateNormal];
        [_continueBtn addTarget:self action:@selector(continueBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _continueBtn;
}
- (UIButton *)cancleBtn{
    if (!_cancleBtn) {
        _cancleBtn = [[UIButton alloc] init];
        [_cancleBtn setTitle:@"关闭" forState:UIControlStateNormal];
        _cancleBtn.titleLabel.font = [UIFont boldSystemFontOfSize:18];
        [_cancleBtn setTitleColor:[UIColor colorWithHex:@"#B0B0B0"] forState:UIControlStateNormal];
        [_cancleBtn addTarget:self action:@selector(cancleBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancleBtn;
}
@end
